package models

import (
	"gorm.io/gorm"
	"types"
)

type Shop struct {
	gorm.Model
	ShopName  string  `gorm:"type:varchar(30);not null;comment:商品名称" json:"shop_name"`
	ShopPrice float64 `gorm:"type:decimal(10,2);not null;comment:商品价格" json:"shop_price"`
	ShopNum   int     `gorm:"type:int(11);not null;comment:商品库存" json:"shop_num"`
	ShopStu   int     `gorm:"type:int(11);not null;comment:商品状态" json:"shop_stu"`
}

// 秒杀时间活动表
type ShopTime struct {
	gorm.Model
	ShopId     int    `gorm:"type:int(11);not null;comment:秒杀商品id" json:"shop_id"`
	TimeZong   string `gorm:"type:varchar(30);not null;comment:商品秒杀的时间段" json:"time_zong"`
	MiaoCreate string `gorm:"type:datetime(3);not null;comment:开始时间" json:"miao_create"`
	MiaoStop   string `gorm:"type:datetime(3);not null;comment:结束时间" json:"miao_stop"`
}

// 添加商品
func (s *Shop) ShopAdd() error {
	return types.Db.Create(&s).Error
}

// 规划秒杀商品时间
func (st *ShopTime) ShopTime() error {
	return types.Db.Create(&st).Error
}

// 秒杀商品展示
func (s *Shop) ShopList() (shop []*Shop, err error) {
	err = types.Db.Find(&shop).Error
	return
}

// 规划秒杀商品时间详情
func (st *ShopTime) ShopTimeInfo() (shoptiem *ShopTime, err error) {
	err = types.Db.Where("shop_id = ? ", st.ShopId).Find(&shoptiem).Error
	return
}
